package 动态查询条件构造器;

import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class 动态查询条件构造器 {
    public static void main(String[] args) {
        List<User> users = Arrays.asList(
                new User("Alice", 25),
                new User("Bob", 30),
                new User("Charlie", 17),
                new User("David", 29)
        );

        // 构建查询条件：用户名含 "a"，且年龄大于 20
        QueryBuilder<User> builder = new QueryBuilder<User>()
                .like(User::getUsername, "a")
                .gt(User::getAge, 20);

        Predicate<User> predicate = builder.build();

        // 使用 collect(Collectors.toList()) 替代 toList()
        List<User> result = users.stream()
                .filter(predicate)
                .collect(Collectors.toList());

        result.forEach(System.out::println);
    }
}